package com.bsoft.gol.hbs.service.impl;

import ctd.spring.boot.annotation.SsdevService;
import ctd.util.annotation.RpcService;
import com.bsoft.gol.hbs.dao.NavigationListSettingsDAO;
import hcn.base.BasePropertyConfig;
import hcn.base.NavigationListSettings;
import hcn.service.base.INavigationListSettingService;
import hcn.service.base.qo.NavigationListSettingQo;
import hcn.util.RpcUserToken;
import org.springframework.beans.factory.annotation.Autowired;
import service.rpc.BasePropertyConfigIntf;
import service.rpc.ServiceOpenIntf;
import com.bsoft.gol.hbs.utils.CommonUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@SsdevService("navigationListSettingsService")
public class NavigationListSettingsService implements INavigationListSettingService {

    private String orgServiceOjectType = "021";
    @Autowired
    private NavigationListSettingsDAO navigationListSettingsDAO;
    @Autowired
    private ServiceOpenIntf serviceOpenService;
    @Autowired
    private BasePropertyConfigIntf basePropertyConfigIntf;
    /**
     * 查询某一条导航列表
     * @param qo
     * @return
     */
    @Override
    @RpcService
    public Map<String,Object> findNavigationListSettingsList(NavigationListSettingQo qo) {
        Map<String,Object> map = new HashMap<>();
        List<NavigationListSettings> list = navigationListSettingsDAO.findNavigationListSettings(qo);
        Long count = navigationListSettingsDAO.getNavigationListSettingsCount(qo.getOrgId());
        map.put("list",list);
        map.put("total",count);
        return map;
    }

    /**
     * 查询某一条导航详情
     * @param settingId
     * @return
     */
    @Override
    @RpcService
    public NavigationListSettings getNavigationListSetting(Long settingId) {

        return navigationListSettingsDAO.getNavigationListSetting(settingId);
    }

    /**
     * 保存
     * @param navigationListSettings
     */
    @Override
    @RpcService
    public void saveNavigationListSetting(NavigationListSettings navigationListSettings) {
        if(0==navigationListSettings.getSettingId()){
            navigationListSettingsDAO.save(navigationListSettings);
        }else{
            navigationListSettingsDAO.update(navigationListSettings);
        }
    }
    /**
     * 查询是否开通导航 并且带入导航参数
     * @param navigationListSettingQo
     * @return
     */
    @Override
    @RpcService
    public Map<String,Object> getNavigationListSettingDetail(NavigationListSettingQo navigationListSettingQo) throws Exception {
            Map<String, Object> map = new HashMap<>();
        List<NavigationListSettings> navigationListSettings = new ArrayList<>();
        if(navigationListSettingQo.getOrgId()==null){
            return null;
        }
        Boolean serviceFlag = serviceOpenService.getServiceByOrgId(RpcUserToken.getTenantId(), "0133",
                navigationListSettingQo.getOrgId());

        BasePropertyConfig propertyConfigByPropertyCode = basePropertyConfigIntf.getPropertyConfigByPropertyCode("013301", navigationListSettingQo.getOrgId());
        if (propertyConfigByPropertyCode != null) {
            map.put("buildingId", propertyConfigByPropertyCode.getPropertyData());
        }

        if (CommonUtils.isNotEmpty(serviceFlag)) {
            map.put("flag", true);
            navigationListSettings = navigationListSettingsDAO.findNavigationListSettingList(navigationListSettingQo);
            map.put("list", navigationListSettings);
        } else {
            map.put("flag", false);
            map.put("list", navigationListSettings);
        }
        return map;
    }


    /**
     * 获取某一个模块的某一个导航属性是否停用
     * @param navigationListSettingQo
     * @return
     */
    @Override
    @RpcService
    public NavigationListSettings getNavigationListSettingForGuideCode(NavigationListSettingQo navigationListSettingQo) {
        NavigationListSettings settings = null;
        List<NavigationListSettings> navigationListSettings = new ArrayList<>();
        navigationListSettings =  navigationListSettingsDAO.findNavigationListSettingList(navigationListSettingQo);
        if(CommonUtils.isNotEmpty(navigationListSettings) && navigationListSettings.size()>0){
            settings = navigationListSettings.get(0);
        }

        return settings;
    }
}
